package com.xuecheng.content.api;

import com.xuecheng.content.model.dto.AddCourseTeacherDto;
import com.xuecheng.content.model.po.CourseTeacher;
import com.xuecheng.content.service.CourseTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author luhao
 * @ClassName CourseTeacherController.java
 * @Description 课程老师接口
 * @createTime 2023/5/30
 */
@RestController
@Api(tags = "课程老师api")
public class CourseTeacherController {
    @Autowired
    private CourseTeacherService courseTeacherService;

    @ApiOperation("查询课程老师信息")
    @GetMapping("/courseTeacher/list/{courseId}")
    public List<CourseTeacher> findCourseTeacherByCourseId(
            @ApiParam(value = "课程Id", required = true) @PathVariable Long courseId) {
        List<CourseTeacher> courseTeacherByCourseId = courseTeacherService.findCourseTeacherByCourseId(courseId);
        return courseTeacherByCourseId;
    }
    @ApiOperation("添加和修改课程老师信息")
    @PostMapping("/courseTeacher")
    public CourseTeacher saveCourseTeacher(@Validated @RequestBody AddCourseTeacherDto dto) {
        // 获取课程机构，本机构才可以添加课程
        Long companyId = 1232141425L;
        CourseTeacher courseTeacher = courseTeacherService.addOrAmendCourseTeacher(companyId, dto);
        return courseTeacher;
    }
    @ApiOperation("删除课程老师信息")
    @DeleteMapping("/courseTeacher/course/{courseId}/{courseTeacherId}")
    public void dropCourseTeacher(
            @ApiParam(value = "课程id",required = true)@PathVariable Long courseId,
            @ApiParam(value = "课程老师id",required = true)@PathVariable Long courseTeacherId){
        // 获取课程机构，本机构才可以添加课程
        Long companyId = 1232141425L;
        courseTeacherService.removeCourseTeacher(courseId, courseTeacherId, companyId);
    }
}
